package com.it.mycharset;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class CharSetDemo1 {
    public static void main(String[] args) throws UnsupportedEncodingException {
        //Java中编码的方法
        //public byte[] getBytes()                       默认
        //public byte[] getBytes(String charsetName)     指定

        //编码
        String str1 = "ai你哦";
        byte[] bytes = str1.getBytes();
        System.out.println(Arrays.toString(bytes));

        byte[] bytes1 = str1.getBytes("GBK");
        System.out.println(Arrays.toString(bytes1));

        //解码
        String str2 = new String(bytes);
        System.out.println(str2);

        String str3 = new String(bytes, "GBK");
        System.out.println(str3);
    }
}
